package cn.hicard.auth.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.hicard.auth.dao.BaseDao;
import cn.hicard.auth.dao.UserRoleDao;
import cn.hicard.auth.entity.MgUserRole;

/**
 * [用户-角色]管理DAO接口实现
 * @author zhangy
 *
 */
@Repository
public class UserRoleDaoImpl extends BaseDao<MgUserRole> implements UserRoleDao{
	@Override
	public List<MgUserRole> getByUser(int pkUserinfo) throws Exception {
		String hql = "FROM MgUserRole WHERE id.pkUserinfo=?";
		return super.findByHql(hql, pkUserinfo);
	}

	@Override
	public void saveUserRoles(List<MgUserRole> userRoles)
			throws Exception {
		super.save(userRoles);
	}

	@Override
	public void deleteByUser(int pkUserinfo) throws Exception {
		String hql = "DELETE FROM MgUserRole WHERE id.pkUserinfo=?";
		super.updateByHqlBulk(hql, pkUserinfo);
	}

	@Override
	public void deleteByRole(int pkRole) throws Exception {
		String hql = "DELETE FROM MgUserRole WHERE id.pkRoleinfo=?";
		super.updateByHqlBulk(hql, pkRole);
	}


	@Override
	public List<Integer> findOwnRolePks(int pkUserinfo) throws Exception {
		String hql = "SELECT id.pkRoleinfo FROM MgUserRole WHERE id.pkUserinfo=?";
		@SuppressWarnings("unchecked")
		List<Integer> list = super.findFieldsByHql(hql, pkUserinfo);
		return list;
	}

}
